<?php
defined( 'BASEPATH' ) or exit( 'No direct script access allowed' );
class Guestbook_handle extends MY_Controller
{
    function check_verify()
    {
        $verify_code = $this->input->get( 'verify_code' );
        $session = MySession::get_instance();
        if (! empty( $verify_code ) && isset( $_SESSION['verify'] ) && strtolower( $verify_code ) === strtolower( $_SESSION['verify'] ))
        {
            echo 'true';
            return;
        }
        echo 'false';
    }
    function save()
    {
        $verify_code = $this->input->post( 'verify_code' );
        $session = MySession::get_instance();
        if (! empty( $verify_code ) && isset( $_SESSION['verify'] ) && strtolower( $verify_code ) === strtolower( $_SESSION['verify'] ))
        {
            unset( $_SESSION['verify'] );
            
            $insert = array ();
            
            $insert['status'] = 0;
            $insert['deleted'] = 0;
            
            $title = $this->input->post( 'title' );
            $insert['title'] = trim( substr_utf8( $title, 50 ) );
            if (empty( $insert['title'] ))
            {
                $this->rs->err( '标题不能为空' );
            }
            
            $content = $this->input->post( 'content' );
            $insert['content'] = trim( substr_utf8( $content, 5000 ) );
            
            $nickname = $this->input->post( 'nickname' );
            $insert['nickname'] = trim( substr_utf8( $nickname, 50 ) );
            
            $sex = ( int ) $this->input->post( 'sex' );
            $insert['sex'] = $sex;
            
            $tel = $this->input->post( 'tel' );
            $insert['tel'] = trim( substr_utf8( $tel, 50 ) );
            
            $email = $this->input->post( 'email' );
            $insert['email'] = trim( substr_utf8( $email, 50 ) );
            
            $qq = $this->input->post( 'qq' );
            $insert['qq'] = trim( substr_utf8( $qq, 50 ) );
            
            $address = $this->input->post( 'address' );
            $insert['address'] = trim( substr_utf8( $address, 255 ) );
            
            $company = $this->input->post( 'company' );
            $insert['company'] = trim( substr_utf8( $company, 255 ) );
            
            $ext1 = $this->input->post( 'ext1' );
            $insert['ext1'] = trim( substr_utf8( $ext1, 255 ) );
            
            $ext2 = $this->input->post( 'ext2' );
            $insert['ext2'] = trim( substr_utf8( $ext2, 255 ) );
            
            $ext3 = $this->input->post( 'ext3' );
            $insert['ext3'] = trim( substr_utf8( $ext3, 255 ) );
            
            $ext4 = $this->input->post( 'ext4' );
            $insert['ext4'] = trim( substr_utf8( $ext4, 255 ) );
            
            $ext5 = $this->input->post( 'ext5' );
            $insert['ext5'] = trim( substr_utf8( $ext5, 255 ) );
            
            $insert['add_time'] = $_SERVER['REQUEST_TIME'];
            
            $this->load->model( 'guestbook_model' );
            if (false !== $this->guestbook_model->insert( $insert ))
            {
                $this->rs->ok();
            }
        }
        else
        {
            $this->rs->err( '验证码错误' );
        }
        $this->rs->err();
    }
}
